package com.hxy.tlias.controller;

import com.hxy.tlias.annotation.Log;
import com.hxy.tlias.pojo.Dept;
import com.hxy.tlias.pojo.Result;


import com.hxy.tlias.service.DeptService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController

public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询部门列表
     * @return
     */
    //@RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping("/depts")
    public Result list(){
        log.info("查询部门列表");
        List<Dept> depts=deptService.list();
        return Result.success(depts);
    }

    /**
     * 删除部门
     * @return
     */
    @Log
    @DeleteMapping("/depts")
    public Result delete(Integer id){
        log.info("删除部门id = {}", id);
        deptService.delete(id);
        return Result.success();
    }
    /**
     * 新增部门
     * @return
     */
    @Log
    @PostMapping("/depts")
    public Result save(@RequestBody Dept dept){
        log.info("新增部门dept = {}", dept);
        
        deptService.save(dept);
        return Result.success();
    }
    /**
     * 根据id查询部门/回显
     * @return
     */
    @GetMapping("/depts/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询部门id = {}", id);
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }

    /**
     * 修改部门
     * @param dept
     * @return
     */
    @Log
    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
        log.info("修改部门dept = {}", dept);
        deptService.update(dept);
        return Result.success();
    }
}
